#include "pch.h"
#include "DefaultSample.h"
#include "DirectXTK\SimpleMath.h"
#include "DirectXTK\DirectXHelpers.h"
#include "Game.h"
using namespace DirectX::SimpleMath;
DefaultSample::DefaultSample(ID3D11Device* device,ID3D11DeviceContext* context) 
    : SampleBase(device,context),isWire(false)
{
    m_states = std::make_unique<CommonStates>(device);

    m_effect = std::make_unique<BasicEffect>(device);
    m_effect->SetVertexColorEnabled(true);

    DX::ThrowIfFailed(
        CreateInputLayoutFromEffect<VertexType>(device, m_effect.get(),
            m_inputLayout.ReleaseAndGetAddressOf())
    );
    m_batch = std::make_unique<PrimitiveBatch<VertexType>>(context);
}

DefaultSample::~DefaultSample()
{

}

void DefaultSample::Update(float dt)
{

}

void DefaultSample::Render()
{
    m_context->OMSetBlendState(m_states->Opaque(), nullptr, 0xFFFFFFFF);
    m_context->OMSetDepthStencilState(m_states->DepthNone(), 0);
    m_context->RSSetState(m_states->CullNone());
    m_effect->Apply(m_context.Get());
    m_context->IASetInputLayout(m_inputLayout.Get());
    VertexPositionColor v1(Vector3(0.f, 0.5f, 0.5f), Colors::Red);
    VertexPositionColor v2(Vector3(0.5f, -0.5f, 0.5f), Colors::Green);
    VertexPositionColor v3(Vector3(-0.5f, -0.5f, 0.5f), Colors::Yellow);

    m_batch->Begin();
    m_batch->DrawTriangle(v1, v2, v3);
    m_batch->End();


}

void DefaultSample::GUI()
{
    ImGui::Begin("DefaultSample");

    ImGui::End();
}

void DefaultSample::DrawFont()
{
    auto game = Game::GetInstance();
    game->GetFont()->Draw("hanshaoqiu", { 1,1,1,1 }, { 0,0 });
}
